package service;

import dao.UserDao;
import domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserDao userDao;

    @Override
    public User login(User user) {
//        System.out.println("进入service login");
        return userDao.login(user);
    }

    //注册用户
    @Transactional
    @Override
    public User regist(User user) {
        //1.根据用户名查询用户对象
        User u = userDao.findByUsername(user.getUsername());
        //判断u（就是一个user对象）是否为null
        if(u != null){
            //用户名存在，注册失败
            return null;
        }
        //2.保存用户信息
        userDao.save(user);
        //异常回滚
        int a = 1/0;

        return user;
    }

}
